跳到主要内容

Seata AT模式使用


一、在方法上增加GlobalTransactional注解即可

   @ApiOperation(value = "操作两张表同库")
@GlobalTransactional
@ResponseBody
@PostMapping(value = "/test1")
public Object test1() {
ExampleRightDatagrid exampleRightDatagrid = new ExampleRightDatagrid();
Integer integer = exampleRightDatagridService.insertSelective(getSaveData(exampleRightDatagrid));
log.info("保存1:{}", integer);
ExampleSingleDatagrid exampleSingleDatagrid = new ExampleSingleDatagrid();
Integer integer1 = exampleSingleDatagridService.insertSelective(getSaveData(exampleSingleDatagrid));
log.info("保存2:{}", integer1);
Integer i = 1 / 0;
return success("1");
}

@ApiOperation(value = "操作两张表不同库")
@GlobalTransactional
@ResponseBody
@PostMapping(value = "/test2")
public Object test2() {
ExampleRightDatagrid exampleRightDatagrid = new ExampleRightDatagrid();
Integer integer = exampleRightDatagridService.insertSelective(getSaveData(exampleRightDatagrid));
log.info("保存1:{}", integer);
ExampleSingleDatagrid exampleSingleDatagrid = new ExampleSingleDatagrid(); //misboot_cloud_vue_zt.example_single_datagrid
Integer integer1 = exampleSingleDatagridService.insertSelective(getSaveData(exampleSingleDatagrid));
log.info("保存2:{}", integer1);
Integer i = 1 / 0;
return success("1");
}

@ApiOperation(value = "操作跨模块调用同库表")
@GlobalTransactional
@ResponseBody
@PostMapping(value = "/test3")
public Object test3() {
Object object = formClient.saveGlobalTransactional();
log.info("保存1:{}", object);
ExampleSingleDatagrid exampleSingleDatagrid = new ExampleSingleDatagrid();
Integer integer = exampleSingleDatagridService.insertSelective(getSaveData(exampleSingleDatagrid));
log.info("保存2:{}", integer);
Integer i = 1 / 0;
return success("1");
}